require 'java'

include_class 'br.com.acme.transaction.PaymentRepository'
include_class 'br.com.acme.transaction.PaymentServiceImpl'
include_class 'br.com.acme.transaction.ValidationService'
include_class 'br.com.acme.user.User'
include_class 'java.math.BigDecimal'


context "in a sucessful transfer" do
  
  before(:each) do 
  @payment_service = PaymentServiceImpl.new    
 
  @payment_repository = mock("PaymentRepository")
  @validation_service  = mock("ValidationService")
  @payment_value = BigDecimal.new("90")
  @debtor = User.new("joe@phoenix.com")
	@creditor = User.new("jane@phoenix.com")     
  
  @payment_service.validation_service = @validation_service
  @payment_service.payment_repository = @payment_repository
    
  end  
    
  it "when a transfer is requested" do   
  
  @payment_repository.should_receive(:addBalance).with(@debtor, @payment_value.negate)      
  @payment_repository.should_receive(:addBalance).with(@creditor, @payment_value)        
  @validation_service.should_receive(:conformsTo).with(@debtor).and_return(true)
  @debtor_balance = @payment_value.add(BigDecimal.new("1"))  
  @payment_repository.should_receive(:findBalance).with(@debtor).and_return(@debtor_balance) 
  
  @payment_service.transfer_from(@debtor, @creditor, @payment_value )  
  end


end
